<?php
namespace Home\Controller;
use Think\Controller;

class ClubController extends PublicController {
	/*俱乐部列表  开发人：周弈男*/
    public function clublist(){
    	$club = M('club');
    	$club = $club->select();
    	$this->assign('club',$club);
    	$this->display();
    }
    /*添加俱乐部页 开发人：周弈男*/
    public function add(){
        $club = M('club');
        if($club->create()){
            if ($_FILES['pic']['error'] == 0) {
                $info = $this->upload();
                $name=$info['pic']['savename'];
            } else {
                $name = "2.jpg";
            }
            $club->pic=$name;
            if (false !== $club->add()) {
                $this->success('添加成功！', '');
            } else {         
                $this->error('数据错误','');           
            }
        }else {            
            $this->error($club->getError());  
        }
    }
    /*实例化上传类 开发人：周弈男*/
    public function upload(){
        $upload = new \Think\Upload();
        $upload->maxSize = 3145728 ;
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
        $upload->rootPath = './Public/photo/';
        $upload->autoSub=false;
        $info = $upload->upload();

        if(!$info) {        
            $this->error($upload->getError());    
        }else{        
           return $info; 
        }                    
    }
    /*删除俱乐部 开发人：周弈男*/
    public function delete(){
        $id=$_GET['clubid'];
        $club=M('club');
        $pic=$club->where("clubid=$id")->find();
        unlink(realpath("./Public/photo/".$pic["pic"]));
        $club=$club->where("clubid=$id")->delete();
        if($club=1){
            $this -> success('删除成功！','');
        }else{
            $this->error('删除失败！','');
        }
    }
}
